require('./Getuserlist.styl');
const classNames = require('classnames');
import { Boxs, Group, NavBar, Scroller } from 'saltui';
import Icon from 'salt-icon'
const { HBox, Box, VBox } = Boxs;
const Valuationclass = require('components/valuationclass')
const Valuationstudent = require('components/valuationstudent')

const components = {
    valuationclass: Valuationclass,
    valuationstudent: Valuationstudent
}
class Select extends React.Component {
    render() {
        if (this.props.selectType == '') return null;
        const SpecificStory = components[this.props.selectType];
        return (
            <SpecificStory
                ref='selectComItem'
                classList={this.props.classList}
                studentList={this.props.studentList}
                selectStudentList={this.props.selectStudentList}
                evaluateList={this.props.evaluateList}
                handleGetUsers={this.props.handleGetUsers}
                refresh={this.props.refresh}
                handleOnRightClick={this.props.handleOnRightClick}
                origin={this.props.origin}
            />);
    }
}
class Getuserlist extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            rightText:props.rightText,
            active: props.active,
            classList: props.classList,
            studentList: props.studentList,
            selectStudentList: props.selectStudentList,
            evaluateList: props.evaluateList
        };
        this.handleOnLeftClick = this.handleOnLeftClick.bind(this)
        this.handleOnRightClick = this.handleOnRightClick.bind(this);
    }
    handleOnLeftClick() {
        this.setState({ active: !this.state.active })
    }

    //右侧导航按钮/选择数据后返回
    handleOnRightClick(origin, users = undefined) {
        if (origin == 'valuationclass') {
            this.setState({ active: !this.state.active })
            this.props.handleGetUsers && this.props.handleGetUsers(users, origin)
        } else {
            let users = this.refs.selectCom.refs.selectComItem.listData;
            if (users && users.length >= 0) {
                this.setState({ active: !this.state.active })
                this.props.handleGetUsers && this.props.handleGetUsers(users, origin)
            }
        }
    }
    render() {
        return (
            <div className={classNames("getuserlist", { active: this.state.active })} >
                <NavBar
                    className="my-navbar"
                    isShow={false}
                    title={this.props.title}
                    onLeftClick={this.handleOnLeftClick}
                    onRightClick={this.handleOnRightClick}
                    rightText={this.state.rightText}
                />
                <Select
                    ref='selectCom'
                    selectType={this.props.selectType}
                    classList={this.state.classList}
                    studentList={this.state.studentList}
                    selectStudentList={this.state.selectStudentList}
                    evaluateList={this.state.evaluateList}
                    handleGetUsers={this.getUsers}
                    refresh={this.props.refresh}
                    handleOnRightClick={this.handleOnRightClick}
                    origin={this.props.origin}
                />
            </div>
        );
    }

    componentWillMount() {
    }

    componentDidMount() {
    }

    componentWillReceiveProps(nextProps) {
        if (nextProps.active != this.state.active) {
            this.setState({ active: nextProps.active,classList:nextProps.classList })
        }
        if (nextProps.studentList != this.state.studentList) {
            this.setState({ studentList: nextProps.studentList })
        }
        if (nextProps.rightText != this.state.rightText) {
            this.setState({ rightText: nextProps.rightText })
        }
        if (nextProps.evaluateList != this.state.evaluateList) {
            this.setState({ evaluateList: nextProps.evaluateList })
        }
        if (nextProps.selectStudentList != this.state.selectStudentList) {
            this.setState({ selectStudentList: nextProps.selectStudentList })
        }
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {
       
    }
}

module.exports = Getuserlist;
